﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DbControl
{
    public class SQLiteControl
    {
        private static string _connetStr = string.Empty;
        static Lazy<IFreeSql> sqLite = new Lazy<IFreeSql>(() =>
        {
            var fsql = new FreeSql.FreeSqlBuilder()
                .UseMonitorCommand(cmd => Trace.WriteLine($"Sql：{cmd.CommandText}"))
                .UseAdoConnectionPool(true)
                .UseConnectionString(FreeSql.DataType.Sqlite, _connetStr) // @"Data Source=|DataDirectory|.\SQLite.db; Attachs=SQLitetb.db; Pooling=true;Min Pool Size=1"
                .UseAutoSyncStructure(true) //自动同步实体结构到数据库，只有CRUD时才会生成表，生产环境需要配置成false
                .Build();
            return fsql;
        });
        public static IFreeSql Sqlite => sqLite.Value;

        public static void SetConnetStr(string str)
        {
            _connetStr = str;
        }
    }
}
